package image

import (
	// "github.com/go-vgo/robotgo"
	"github.com/vova616/screenshot"
	"image"
	"image/png"
	"log"
	"os"
)

type Point struct {
	X int
	Y int
}

func GenerateScreenByBitMap(imagePath string) {
	// bitmap := robotgo.CaptureScreen(point.X, point.Y, 227, 130)
	// defer robotgo.FreeBitmap(bitmap)
	// robotgo.SaveBitmap(bitmap, imagePath)
	rect := image.Rect(200, 500, 600, 700)
	log.Println(rect.String())
	img, err := screenshot.CaptureRect(rect)
	if err != nil {
		log.Fatalln("截图失败 {}", err)
	}

	save(img, imagePath)

}

// save *image.RGBA to filePath with PNG format.
func save(img *image.RGBA, filePath string) {
	os.Remove(filePath)
	file, err := os.Create(filePath)
	if err != nil {
		log.Fatalln(err)
	}
	defer file.Close()
	png.Encode(file, img)
}
